﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityGameFramework.Runtime;
using GameFramework.Event;
using UnityEngine.UI;
using TowerDefence_Zombie.Data;
using GameFramework;

namespace TowerDefence_Zombie
{
    public class UIGameOverForm : UGuiFormEx
    {
        [SerializeField, Header("关闭按钮")] private Button m_CloseButton;
        protected override void OnInit(object userData)
        {
            base.OnInit(userData);
            m_CloseButton.onClick.AddListener(ClosePanel);
        }

        protected override void OnOpen(object userData)
        {
            base.OnOpen(userData);

            //UIGameOverFormOpenParam uIGameOverFormOpenParam = userData as UIGameOverFormOpenParam;
            //if (uIGameOverFormOpenParam == null)
            //{
            //    Log.Error("UIGameOverForm open param tyoe invaild");
            //    return;
            //}
            //ReferencePool.Release(uIGameOverFormOpenParam);
            GameEntry.Sound.PlaySound(EnumSound.DefeatedMusic, null);
            Invoke(nameof(ClosePanel), 3f);
        }

        protected override void OnClose(bool isShutdown, object userData)
        {
            base.OnClose(isShutdown, userData);
        }

        public void OnNextLevelButtonClick()
        {

        }

        public void OnMainMenuButtonClick()
        {
            //GameEntry.Data.GetData<DataLevel>().ExitLevel();
        }

        public void ClosePanel()
        {
            //int currentLevel = GameEntry.Data.GetData<DataLevel>().CurrentLevelIndex;
            //GameEntry.Data.GetData<DataLevel>().LoadLevel(currentLevel);
            Close();
            GameEntry.Event.Fire(this, StartWaveEventArgs.Create());
        }
    }
}
